﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Text;

namespace ConsoleApplication1
{
    public class Program
    {
        public static void Main(string[] args)
        {
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write("{0}*{1}={2}  ", i, j, i * j);
                }
                Console.WriteLine();
            }
            Console.WriteLine();
            GetSQLDemo();
            //Console.WriteLine("面向过程输出星期几:");
            //GetXQ();
            //Console.WriteLine();
            //Console.WriteLine("面向对象输出星期几:");
            //Console.Write("请按照格式 XXXX-XX-XX 输入年月日： ");
            //CalcWeekDay myCalcWeekDay = new CalcWeekDay();
            //String strDate = Console.ReadLine().Trim();
            //String[] strDates = strDate.Split(new char[] { '-' });
            //int temp = 0;
            //if (Int32.TryParse(strDates[0], out temp))
            //{
            //    myCalcWeekDay.Year = Int32.Parse(strDates[0]);
            //}
            //if (Int32.TryParse(strDates[1], out temp))
            //{
            //    myCalcWeekDay.Month = Int32.Parse(strDates[1]);
            //}
            //if (Int32.TryParse(strDates[2], out temp))
            //{
            //    myCalcWeekDay.Day = Int32.Parse(strDates[2]);
            //}
            //Console.WriteLine();
            //Console.WriteLine();
            ////打印星期几
            //myCalcWeekDay.PrintWeekDayByDate();
            //Console.WriteLine(); 
            //myCalcWeekDay.PrintWeekDay();

            //Console.WriteLine(); Console.WriteLine();
            //List<Student> list = new List<Student>()
            //{ 
            //    new Student{ SAddress="成都市", SName="张三", SNO=10 },
            //    new Student{ SNO=11, SName="李四", SAddress="北京市"},
            //    new Student{SAddress="重庆市", SName="成龙", SNO=12}
            //};
            //foreach (Student stu in list)
            //{
            //    Console.WriteLine("姓名:{0}   地址:{0}  编号:{2}", stu.SName, stu.SAddress, stu.SNO);
            //}
            //Console.WriteLine();

            //Student stu1 = new Student();
            //stu1.SName = "张三";
            //stu1.SNO = 13;
            //stu1.SAddress = "广西省XX市";
            //stu1.Show();


            B b = new B("张三");
            b.show();

            Console.ReadKey();
        }

        /// <summary>
        ///  //万年历 1900.1.1 星期一 
        ///  打出2010-5 月的日历
        ///  1、5月1号是星期几？
        ///  2、1900.1.1--1.7=7天%7+1就是星期几
        ///  3、总天数=（1990--2009）*365（算上闰年）+2010年1.1--4.30的总天数  
        ///  4、y%400||（y%4==0&&y%100!=0）的就是闰年
        ///  5、m小于5的话，叠加后续的数值
        /// </summary>
        public static void GetXQ()
        {
            int totalDay = 0;

            #region 求天数第一部分
            for (int y = 1900; y <= 2009; y++)
            {
                if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))
                {
                    totalDay += 366;
                }
                else
                {
                    totalDay += 365;
                }
            }
            #endregion

            #region 求天数第二部分
            for (int m = 1; m <= 4; m++)
            {
                switch (m)
                {
                    case 1:
                        totalDay += 31;
                        break;
                    case 2:
                        totalDay += 28;
                        break;
                    case 3:
                        totalDay += 31;
                        break;
                    case 4:
                        totalDay += 30;
                        break;
                    case 5:
                        totalDay += 31;
                        break;
                    case 6:
                        totalDay += 30;
                        break;
                    case 7:
                        totalDay += 31;
                        break;
                    case 8:
                        totalDay += 31;
                        break;
                    case 9:
                        totalDay += 30;
                        break;
                    case 10:
                        totalDay += 31;
                        break;
                    case 11:
                        totalDay += 30;
                        break;
                    case 12:
                        totalDay += 31;
                        break;
                    default:
                        break;
                }
            }
            #endregion

            #region 打印星期几
            Console.WriteLine("总天数：{0}", totalDay + 1);
            switch ((totalDay + 1) % 7 + 1)
            {
                case 1:
                    Console.WriteLine("星期日");
                    break;
                case 2:
                    Console.WriteLine("星期一");
                    break;
                case 3:
                    Console.WriteLine("星期二");
                    break;
                case 4:
                    Console.WriteLine("星期三");
                    break;
                case 5:
                    Console.WriteLine("星期四");
                    break;
                case 6:
                    Console.WriteLine("星期五");
                    break;
                case 7:
                    Console.WriteLine("星期六");
                    break;
                default:
                    break;
            }
            #endregion
        }

        public static void GetSQLDemo()
        {
            string strConnn = @"server=TYL\MSSQLERVER2008;database=DBTestDemo;integrated security=SSPI;";
            SqlConnection conn = new SqlConnection(strConnn);
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from tbTest");
            SqlDataReader DataReader =  cmd.ExecuteReader( System.Data.CommandBehavior.CloseConnection);
            while (DataReader.Read())
            {
                int id = (int)DataReader["ID"];
                string id_Name = (string)DataReader["ID_Name"];
                Console.WriteLine("ID:{0}   ID_Name:{1}",id,id_Name);
            }
            DataReader.Close();
            conn.Close();
        }



    }
}
